package com.youtills.core.calc;

/**
 * Created by IntelliJ IDEA.
 * User: rchiluve
 * Date: 2/8/14
 * Time: 7:47 PM
 * To change this template use File | Settings | File Templates.
 */
public class Loan {

    private double principal;
    private double rate;
    private int term;
    private double payment;
    private PaymentType paymentType = PaymentType.MONTH;

    public static enum PaymentType {
        MONTH,
        SEMI_MONTH
    }

    public Loan(){};
    public Loan(double principal, double rate, int term) {
        this.principal = principal;
        this.rate = rate;
        this.term = term;
    }

    public double getPrincipal() {
        return principal;
    }

    public void setPrincipal(double principal) {
        this.principal = principal;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public int getTerm() {
        return term;
    }

    public void setTerm(int term) {
        this.term = term;
    }

    public void calculatePayment(){
        double R;
        switch (paymentType){
            case MONTH:
                R = rate / 1200;
                break;
            case SEMI_MONTH:
                R = rate / 2400;
                break;
            default:
                throw new RuntimeException("PaymentType Not found");
        }

        //W = =(1+R)^term
        //Payment = (R x P x W)/(W - 1)
        //P = principal; W = above; R = above;
        double W = Math.pow((1 + R), term);

        payment = (R * principal * W) / (W - 1);

    }

    public double getPayment() {
        return payment;
    }
}
